<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        arr = [1, 5, 3]
        Array.prototype.mySort = function (fn) {
            let fn1 = fn(2, 1)
            for (let i = 0; i < this.length - 1; i++) {
                for (let j = 0; j < this.length - i - 1; j++) {
                    if (fn1 > 0) {
                        if (arr[j] > arr[j + 1]) {
                            let temp = arr[j]
                            arr[j] = arr[j + 1]
                            arr[j + 1] = temp
                        }
                    }
                    if (fn1 < 0) {
                        if (arr[j] < arr[j + 1]) {
                            let temp = arr[j]
                            arr[j] = arr[j + 1]
                            arr[j + 1] = temp
                        }
                    }

                }
            }
            return this
        }
        console.log(arr.mySort(function (a, b) {
            return a - b
        }));
    </script>
</body>

</html>